package com.tally.server.service;

import com.tally.server.domain.SysLevel;
import com.tally.server.domain.SysLevelExample;
import com.tally.server.dto.ExpDTO;
import com.tally.server.dto.SysLevelDTO;
import com.tally.server.dto.PageDTO;
import com.tally.server.mapper.SysLevelMapper;
import com.tally.server.utils.CopyUtil;
import com.tally.server.utils.UUIDUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class SysLevelService {

    @Autowired
    private SysLevelMapper sysLevelMapper;

    public Integer getLevel(ExpDTO expDTO) {
        SysLevelExample sysLevelExample = new SysLevelExample();
        sysLevelExample.createCriteria().andMaxExpGreaterThan(expDTO.getExp());
        sysLevelExample.setOrderByClause("level");
        List<SysLevel> sysLevelList = sysLevelMapper.selectByExample(sysLevelExample);
        if(!CollectionUtils.isEmpty(sysLevelList)){
            return sysLevelList.get(0).getLevel();
        }
        return 10;
    }


    public Integer getMaxExp(Integer level) {
        SysLevelExample sysLevelExample = new SysLevelExample();
        sysLevelExample.createCriteria().andLevelEqualTo(level);
        List<SysLevel> sysLevelList = sysLevelMapper.selectByExample(sysLevelExample);
        if(!CollectionUtils.isEmpty(sysLevelList)){
            return sysLevelList.get(0).getMaxExp();
        }
        return 0;
    }
}
